package com.example.alibabanacosdiscoveryclient01.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.ai.image.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author:guoq
 * @date:2024/6/27
 * @descripion:
 */
@RestController
@RequestMapping("/ai")
@Tag(name = "imageAI应用")
public class ImageAiController {
    @Autowired
    private ImageModel imageModel;

    @GetMapping("/image")
    @Operation(summary = "文生图")
    public String image(String input) {
        ImageOptions options = ImageOptionsBuilder.builder()
//                .withModel("wanx-v1")
                .model("wanx-v1")
                .build();

        ImagePrompt imagePrompt = new ImagePrompt(input, options);
        ImageResponse response = imageModel.call(imagePrompt);
        String imageUrl = response.getResult().getOutput().getUrl();

        return "redirect:" + imageUrl;
    }
}
